# Copyright (C) 2006,2007  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#

use strict;
use warnings;

package CCNCore::Model::ServerNetwork;

use Jifty::DBI::Schema;

use CCNCore::Record schema {

    column server =>
        references CCNCore::Model::Server,
        is mandatory,
        is immutable,
        is indexed,
        label is "Server",
        hints is '';

    column ipnet_ip =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Type::IPv4::validator,
        is mandatory,
        is immutable,
        is indexed,
        since '0.0.1',
        label is "DHCP/NTP network IP";

    column ipnet_mask =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Type::IPv4::validator,
        is mandatory,
        is immutable,
        since '0.0.1',
        label is "DHCP/NTP network mask";


    column ntp =>
        type is 'boolean',
        valid_values are
            { display => '', value => undef },
            { display => 'Yes', value => 'TRUE' },
            { display => 'No',  value => 'FALSE' },
        since '0.0.1',
        label is "Provide NTP services for this subnet?";

    column dhcp =>
        type is 'boolean',
        valid_values are
            { display => '', value => undef },
            { display => 'Yes', value => 'TRUE' },
            { display => 'No',  value => 'FALSE' },
        since '0.0.1',
        label is "Provide DHCP services for this subnet?";


    # XXX @timezone
    column timezone =>
        type is 'TEXT',
        since '0.0.1',
        label is "DHCP timezone";

    column range_start =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Type::IPv4::validator,
        since '0.0.1',
        label is "DHCP range start";

    column range_end =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Type::IPv4::validator,        
        since '0.0.1',
        label is "DHCP range end";

    column router =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Type::IPv4::validator,
        since '0.0.1',
        label is "DHCP default gateway";

    # XXX PRIMARY KEY ("server","ipnet_ip")

};

use CCNCore::Mixin::Active;

sub since { 0.0.1 }
sub authorize_via { qw( server server ) }
sub menu { 'Servers' }

1;

__END__

=pod
-- This is used for DHCP and NTP

CREATE TABLE "server_network" (
    -- key
    "server"        INTEGER NOT NULL REFERENCES server(pk),     --      "Server"
    "ipnet_ip"      inet NOT NULL,                      -- @ip          "DHCP/NTP network IP"
    "ipnet_mask"    inet NOT NULL,                      -- @ip          "DHCP/NTP network mask"

    -- provisioning
    "ntp"           BOOLEAN,                            -- @boolean     "Provide NTP services?"     dontlist
    "dhcp"          BOOLEAN,                            -- @boolean     "Provide DHCP services?"    dontlist

    "timezone"      TEXT,                               -- @timezone    "DHCP timezone"             dontlist
    "range_start"   inet,                               -- @ip          "DHCP range start"          dontlist
    "range_end"     inet,                               -- @ip          "DHCP range end"            dontlist
    "router"        inet,                               -- @ip          "DHCP default gateway"      dontlist

    --
    PRIMARY KEY ("server","ipnet_ip")
);

=cut